<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>考试培训后台管理</title>
</head>
<link href="../static/plugin/layui/css/layui.css" rel="stylesheet"/>
<script type="text/javascript" src="../static/plugin/layui/layui.js"></script>
<script type="text/javascript" src="../static/js/common.js"></script>
<body>
<form class="layui-form layui-form-pane" action="store/updatestore" method="post" >
    <input id="stuId" name="stuId" type="hidden">
    <div class="layui-form-item" style="margin-top: 15px;margin-left: 30px;">
        <label class="layui-form-label">学号</label>
        <div class="layui-input-inline">
            <input type="text" name="stuXuehao" id="stuXuehao" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
        </div>
        <label class="layui-form-label">真实名称</label>
        <div class="layui-input-inline">
            <input type="text" name="stuRealname" id="stuRealname"   lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item" style="margin-top: 15px;margin-left: 30px;">
        <label class="layui-form-label">性别</label>
        <div class="layui-input-inline">
            <select name="stuSex" id="stuSex" id="teaSex" lay-verify="">
                <option value="0">女</option>
                <option value="1">男</option>
            </select>
        </div>
        <label class="layui-form-label">年龄</label>
        <div class="layui-input-inline">
            <input type="text" name="stuAge" id="stuAge"   lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item" style="margin-top: 15px;margin-left: 30px;">
        <label class="layui-form-label">卡号</label>
        <div class="layui-input-inline">
            <input type="text" name="stuCard" id="stuCard" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
        </div>
        <label class="layui-form-label">政治面貌</label>
        <div class="layui-input-inline">
            <select name="stuZhengzhimianmao" id="stuZhengzhimianmao" lay-verify="">
                <option value="0">党员</option>
                <option value="1">团员</option>
                <option value="2">群众</option>
            </select>
        </div>
    </div>


    <div class="layui-form-item" style="margin-top: 15px;margin-left: 30px;">
        <label class="layui-form-label">登录名</label>
        <div class="layui-input-inline">
            <input type="text" name="loginName" id="loginName" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
        </div>
        <label class="layui-form-label">登录密码</label>
        <div class="layui-input-inline">
            <input type="text" name="loginPw" id="loginPw"   lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item" >
        <div class="layui-input-block" align="center">
            <button class="layui-btn" lay-submit="" lay-filter="saveOrAdd">保存</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
</body>
<script type="text/javascript">
    layui.use([ 'form', 'layer', 'table','upload' ], function() {
        var table = layui.table, $ = layui.$, form = layui.form;
        //编辑时候赋值
        var urlParam = getParam('stuId');
        log(urlParam)
        if (!isEmpty(urlParam)) {
            $.ajax({
                url: "student/getStudent",
                data: {"stuId": urlParam},
                type: "POST",
                dataType: "json",
                success: function (msg) {
                    log(msg);
                    var json = msg;
                    for (var key in json) {
                        $("#" + key + "").val(json[key]);
                    }
                    form.render('select');
                }
            });
        }

        //监听编辑或者添加
        form.on('submit(saveOrAdd)', function(data){
            var url = $("#stuId").val() == "" ?"student/add" : "student/update";
            var datas=data.field;
            $.ajax({
                url:url,
                data: JSON.stringify(datas),
                type: "POST",
                dataType: "json",
                contentType: "application/json;charset=UTF-8",
                success:function(msg){
                    if(msg===1){
                        layer.msg('修改成功，正在跳转......', {icon: 6});
                        //parent.layer.close(index);
                        setTimeout(function () {
                            window.parent.location.reload();
                        }, 1000);

                    }else{
                        layer.msg('修改失败', { icon: 5 });
                    }
                },
                error:function(error){
                    layer.msg('系统异常！请联系管理员', { icon: 5 });
                }
            });
            return false;
        });

    });
</script>
</html>